package com.example.nfctagcommons.controllers;

import java.lang.reflect.Type;
import java.util.List;

import android.app.Activity;

import com.example.nfctagcommons.classes.PointCheck;
import com.example.nfctagcommons.exceptions.ConnectivityException;
import com.example.nfctagcommons.server.HttpsExecuter;
import com.example.nfctagcommons.server.ServerInfo;
import com.example.nfctagcommons.utils.StringPool;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class VigilanceLocalCheckHistoryController {
	private static final Gson gson = new Gson();

	
	public static boolean setLocalChecked(Activity activity, String guardId, String localId, String checkComments, long time) throws ConnectivityException{
		String completeURL = ServerInfo.SERVER_HOST+ServerInfo.SERVICES_PATH;
		String query = "guardId="+guardId+"&operation=setLocalChecked&localId="+localId+"&checkComments="+checkComments+"&time="+time;
		String response = HttpsExecuter.execute(activity, completeURL, query, true);
		return response.contains(StringPool.TRUE);
	}
	
	public static List<PointCheck> getVigilanceLocalHistory(Activity activity, String guardId) throws ConnectivityException{
		String completeURL = ServerInfo.SERVER_HOST+ServerInfo.SERVICES_PATH;
		String query = "operation=getVigilanceLocalHistory&guardId="+guardId;
		String response = HttpsExecuter.execute(activity, completeURL, query, true);
		try{
        	Type t = new TypeToken<List<PointCheck>>(){}.getType();
        	List<PointCheck> list = gson.fromJson(response, t);
	        return list;
        }catch (Exception x){
        	x.printStackTrace();
        	return null;
        }
	}
}
